package com.example.community.update;

import com.example.community.dao.RepairDao;
import com.example.community.model.Repair;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.HttpCookie;

/**
 * 处理维修
 */
@WebServlet(urlPatterns = "/handleRepairServlet")
public class HandleRepairServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reNo = req.getParameter("reNo");
        req.setAttribute("reNo",reNo);
        req.getRequestDispatcher("/WEB-INF/communityService/handleRepair.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String reNo = req.getParameter("reNo");
            String desc = req.getParameter("desc");

            RepairDao repairDao = new RepairDao();
            Repair repair = repairDao.fandById(Integer.parseInt(reNo));
            repair.setReResult(desc);
            repair.setReState("已处理");

            Integer update = repairDao.update(repair);
            if (update == 1){
                resp.getWriter().write("true");
            }else {
                resp.getWriter().write("false");
            }
        }catch (Exception e){
            resp.getWriter().write("false");
        }
    }
}
